package com.four.controller;


import com.four.pojo.*;
import com.four.service.IMiddleService;
import com.four.service.impl.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author 于志豪
 * @create 2021-10-24 17:26
 */

@Controller

public class OrdersController {
    @Autowired
    @Qualifier("ordersServiceImpl")
    private OrdersServiceImpl service;

    @Autowired
    @Qualifier("serviceServiceImpl")
    private ServiceServiceImpl service1;

    @Autowired
    @Qualifier("ordersSerImpl")
    private OrdersSerImpl ordersSer;

    @Autowired
    @Qualifier("productService")
    private ProductServiceImpl iProductService;//商品

    @Autowired
    @Qualifier("staffSerImpl")
    private StaffSerImpl staffSer;//员工

    @Autowired
    @Qualifier("car_psServiceImpl")
    private Car_psServiceImpl car_psService;//车属性


    @RequestMapping("/deleteMid__")
    public String deleteMid(int id){//删除订单

        service.deleteOid(id);
        return "redirect:/findAllOrd";

    }


    @RequestMapping("/addOrders")
    public String addOrders(Orders orders){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();

        int num=(int)(Math.random()*999999999);

        orders.setO_number(num);
        orders.setD_time(sdf.format(date));

        service.addOrder(orders);//添加订单

        return "/new_Order.jsp";
    }

    @RequestMapping("/findAddSer")//车属性    选择服务
    public String findCar (Model model,int id){
        List<Car_ps> car_ps = car_psService.findCar_ps();//车属性
        model.addAttribute("car_ps",car_ps);

        List<Service> all = service1.findAll();
        model.addAttribute("all",all);//服务下拉

        List<Staff> Serxs = staffSer.findXS();//销售
        List<Staff> Sersg = staffSer.findSG();//施工
        model.addAttribute("Serxs",Serxs);
        model.addAttribute("Sersg",Sersg);
        model.addAttribute("id",id);
        return "choose_ServeAdd.jsp";
    }


    @RequestMapping("/findSPLB")
    public String findSPLB(Model model,int id){//添加商品

        List<Product> allProduct = iProductService.findAllProduct();
        model.addAttribute("allProduct",allProduct);

        List<Staff> xs1 = staffSer.findXS();
        model.addAttribute("xs1",xs1);

        model.addAttribute("id",id);
        return "new_OrderAdd.jsp";
    }

    @RequestMapping("/findAllOrd")
    public String findAll (Model model,Orders orders){//订单列表
        List<Orders> all = service.findAll(orders);
        model.addAttribute("all",all);

        return "order_List.jsp";
    }

    //编辑订单
    @RequestMapping(value = "/findThreeBJ")
    public String findThreeBJ(Model model,int id){
        List<Product> all1 = ordersSer.findAll(id);
        model.addAttribute("all1",all1);//商品

        List<Service> all4 = service1.findById(id);//服务
        model.addAttribute("all4",all4);

        Orders byId = service.findById(id);
        model.addAttribute("byId",byId);//订单号

        return "order_edit.jsp";
    }


    //查看详情
    @RequestMapping(value = "/findThree")
    public String findThree(Model model,int id){
        System.out.println(id);

        List<Product> all1 = ordersSer.findAll(id);
        model.addAttribute("all1",all1);//商品

        System.out.println(id);
        List<Service> all = service1.findById(id);//服务
        System.out.println(all);
        model.addAttribute("all",all);

        Orders byId = service.findById(id);
        model.addAttribute("byId",byId);

        return "order_Detail.jsp";
    }

}
